# Copyright 2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit desktop unpacker

DESCRIPTION="Zulip Desktop App"
HOMEPAGE="https://github.com/zulip/zulip-desktop"
SRC_URI="https://github.com/zulip/zulip-desktop/releases/download/v${PV}/Zulip-${PV}-amd64.deb"
S="${WORKDIR}"

LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="amd64"

DEPEND="
app-crypt/libsecret
dev-libs/nss
net-print/cups
sys-apps/dbus
sys-apps/util-linux
sys-libs/glibc
x11-libs/cairo
x11-libs/gtk+:3
x11-libs/libdrm
x11-libs/libXScrnSaver
x11-libs/pango
"
RDEPEND="${DEPEND}"
BDEPEND=""

DESTDIR="/opt/Zulip"

src_unpack() {
	unpack_deb Zulip-${PV}-amd64.deb
}

src_prepare() {
	default
	rm -rf etc/ || die
}

src_install() {
	doicon -s 256 usr/share/icons/hicolor/256x256/apps/${PN}.png
	domenu usr/share/applications/${PN}.desktop

	cd opt/Zulip
	exeinto "${DESTDIR}"
	doexe zulip chrome_crashpad_handler chrome-sandbox libEGL.so libffmpeg.so libGLESv2.so libvk_swiftshader.so

	insinto "${DESTDIR}"
	doins chrome_100_percent.pak chrome_200_percent.pak icudtl.dat resources.pak snapshot_blob.bin v8_context_snapshot.bin
	insopts -m0755
	doins -r locales resources
	# Chrome-sandbox requires the setuid bit to be specifically set.
	# see https://github.com/electron/electron/issues/17972
	fowners root "${DESTDIR}/chrome-sandbox"
	fperms 4711 "${DESTDIR}/chrome-sandbox"
}
